package org.hncors.gnssparse;

import android.content.Context;
import android.content.ContextWrapper;
import android.content.SharedPreferences;

/**
 * Created by PC8681 on 2018/1/5.
 */
public class ProgramConfigWrapper {
    private ContextWrapper mWrapper = null;
    private SharedPreferences mPreferences = null;
    private volatile static ProgramConfigWrapper m_ProgramConfig = null;

    private String mstrNTRIPParaIP = "219.135.151.189";
    private int mnNTRIPParaPort = 2018;
    private String mstrNTRIPParaUserName = "";
    private String mstrNTRIPParaPassword = "";
    private String mstrNTRIPParaMountPoint = "";

    private int connectType = 0;
    private String bluetoothName = "";
    private String bluetoothAddress = "";

    //单例模式获取实例
    public static ProgramConfigWrapper GetInstance(Context base) {
        if (m_ProgramConfig == null) {
            synchronized (ProgramConfigWrapper.class){
                if (m_ProgramConfig == null){
                    m_ProgramConfig = new ProgramConfigWrapper(base);
                    m_ProgramConfig.init();
                }
            }
        }

        return m_ProgramConfig;
    }
    private void init(){
        m_ProgramConfig.mstrNTRIPParaIP = m_ProgramConfig.mPreferences.getString("Config_NTRIPParaIP", "219.135.151.189");
        m_ProgramConfig.mnNTRIPParaPort = m_ProgramConfig.mPreferences.getInt("Config_NTRIPParaPort", 2018);
        m_ProgramConfig.mstrNTRIPParaUserName = m_ProgramConfig.mPreferences.getString("Config_NTRIPParaUserName", "");
        m_ProgramConfig.mstrNTRIPParaPassword = m_ProgramConfig.mPreferences.getString("Config_NTRIPParaPassword", "");
        m_ProgramConfig.mstrNTRIPParaMountPoint = m_ProgramConfig.mPreferences.getString("Config_NTRIPParaMountPoint", "RTCM30");

        m_ProgramConfig.connectType = m_ProgramConfig.mPreferences.getInt("connectType", 0);
        m_ProgramConfig.bluetoothName = m_ProgramConfig.mPreferences.getString("BluetoothName", "58.248.35.130");
        m_ProgramConfig.bluetoothAddress = m_ProgramConfig.mPreferences.getString("BluetoothAddress", "58.248.35.130");
    }
    public ProgramConfigWrapper(Context base) {
        //super(base);
        mWrapper = new ContextWrapper(base);
        mPreferences = mWrapper.getSharedPreferences("Perference",ContextWrapper.MODE_PRIVATE);
    }

    //设置NIRIP网络参数
    public void SetNTRIPPara(String strIP, int nPort,
                             String strUserName, String strPassword, String strMountPoint) {
        SharedPreferences.Editor editor = mPreferences.edit();
        editor.putString("Config_NTRIPParaIP", strIP);
        editor.putInt("Config_NTRIPParaPort", nPort);
        editor.putString("Config_NTRIPParaUserName", strUserName);
        editor.putString("Config_NTRIPParaPassword", strPassword);
        editor.putString("Config_NTRIPParaMountPoint", strMountPoint);
        editor.commit();
        mstrNTRIPParaIP = strIP;
        mnNTRIPParaPort = nPort;
        mstrNTRIPParaUserName = strUserName;
        mstrNTRIPParaPassword = strPassword;
        mstrNTRIPParaMountPoint = strMountPoint;
    }
    //IP
    public String GetNTRIPParaIP() {
        return mstrNTRIPParaIP;
    }
    //端口
    public int GetNTRIPParaPort() {
        return mnNTRIPParaPort;
    }
    //用户名
    public String GetNTRIPParaUserName() {
        return mstrNTRIPParaUserName;
    }
    //密码
    public String GetNTRIPParaPassword() {
        return mstrNTRIPParaPassword;
    }
    //接入点
    public String GetNTRIPParaMountPoint() {
        return mstrNTRIPParaMountPoint;
    }

    public void SetConnectType(int connectType) {
        SharedPreferences.Editor editor = mPreferences.edit();
        editor.putInt("connectType", connectType);
        editor.commit();
        this.connectType = connectType;
    }

    public int GetConnectType() {
        return connectType;
    }

    public void SetBluetoothName(String strBluetoothName) {
        SharedPreferences.Editor editor = mPreferences.edit();
        editor.putString("BluetoothName", strBluetoothName);
        editor.commit();
        bluetoothName = strBluetoothName;
    }

    public String GetBluetoothName() {
        return bluetoothName;
    }

    public void SetBluetoothAddress(String strBluetoothAddress) {
        SharedPreferences.Editor editor = mPreferences.edit();
        editor.putString("BluetoothAddress", strBluetoothAddress);
        editor.commit();
        bluetoothAddress = strBluetoothAddress;
    }

    public String GetBluetoothAddress() {
        return bluetoothAddress;
    }
}
